package view;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;

import controller.MenueController;

public class AuswRelaistyp extends JDialog implements ActionListener {

	private MenueController menueController;

	private String id; // von welcher tabelle
	
	private JButton btnRelaisGross;
	private JButton btnRelaisKlein;
	private JButton btnAbbrechen;

	private JPanel pnlRelaistyp;

	/**
	 * Konstruktor
	 */
	public AuswRelaistyp(MenueController menueController, String id) {
		super();

		setTitle("Auswahl Relaistyp");
		setLayout(new BorderLayout(5, 5));

		setPreferredSize(new Dimension(200, 100));
		
		this.menueController = menueController;
		this.id = id;
		
		initWidgets();

		addWidgets();
		
		setModal(true);
		
		setLocationRelativeTo(null);
		
		pack();
		setVisible(true);

	}

	/**
	 * 
	 */
	private void initWidgets() {
		pnlRelaistyp = new JPanel(new GridLayout(1, 2, 5, 5));

		btnRelaisGross = new JButton("Gross");
		btnRelaisGross.addActionListener(this);

		btnRelaisKlein = new JButton("Klein");
		btnRelaisKlein.addActionListener(this);

		btnAbbrechen = new JButton("Abbrechen");
		btnAbbrechen.addActionListener(this);

	}

	/**
	 * 
	 */
	private void addWidgets() {
		pnlRelaistyp.add(btnRelaisGross);
		pnlRelaistyp.add(btnRelaisKlein);

		add(BorderLayout.NORTH, pnlRelaistyp);

		add(BorderLayout.CENTER, btnAbbrechen);

	}

	/**
	 * 
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		// Button relaistyp gross
		if (e.getSource() == btnRelaisGross) {
			menueController.auswRelaistyp(id, "Gross");
			setVisible(false);
		}

		// Button Relaistyp klein
		if (e.getSource() == btnRelaisKlein) {
			menueController.auswRelaistyp(id, "Klein");
			setVisible(false);
		}

		// Button Abbrechen
		if (e.getSource() == btnAbbrechen) {
			setVisible(false);
		}
	}

}
